﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web;
using NLBS.Control;
using NLBS.Entity;
using NLBS.Data.Business;
using NLBS.Data;
using NLBS.Security;
using System.Web.Security;
using NLBS.Framework;
namespace NLBS.Web.UI
{
    public class CallBackHelp : CallBackBase
    {
        public Dictionary<string,ICommand> commands;


        public void CreateCommand()
        {
            commands = new Dictionary<string, ICommand>();
            commands.Add("panelCategory", new ControlCommand(new PanelCategory(), this));
            commands.Add("panelArticle", new ControlCommand(new PanelArticle(), this));
            commands.Add("panelComment", new ControlCommand(new PanelComment(), this));
            commands.Add("panelArchive", new ControlCommand(new PanelArchive(), this));
            commands.Add("panelGuestBook", new ControlCommand(new PanelGuestBook(), this));
            commands.Add("panelLink", new ControlCommand(new PanelLink(), this));
            commands.Add("panelStats", new ControlCommand(new PanelStatus(), this));
            commands.Add("panelUser", new ControlCommand("/Control/panelUser.ascx", this));
            commands.Add("articleList", new ControlCommand("/Control/content.ascx", this));
            commands.Add("singleArticle", new ControlCommand("/Control/firstContent.ascx", this));
            commands.Add("guestbooklist", new ControlCommand("/Control/guestbook.ascx", this));
            commands.Add("commentlist", new ControlCommand("/Control/comment.ascx", this));
            commands.Add("trackbacklist", new ControlCommand("/Control/trackBack.ascx", this));
            commands.Add("userlist", new ControlCommand("/Control/user.ascx", this));
            commands.Add("userDetails", new ControlCommand("/Control/userDetails.ascx", this));
            commands.Add("registerView", new ControlCommand("/Control/register.ascx", this));
            commands.Add("articleCommentList", new ControlCommand("/Control/commentList.ascx", this));
            commands.Add("visitors", new ControlCommand("/Control/stats.ascx", this));

            commands.Add("tagcloud", new ControlCommand("/Control/tags.ascx", this));
            commands.Add("addcomment", new CommentCommand(Action.Insert,this));
            commands.Add("deleteComment", new CommentCommand(Action.Delete,this));
            commands.Add("addGuestBook", new GuestBookCommand(Action.Insert, this));
            commands.Add("deleteGuestBook", new GuestBookCommand(Action.Delete, this));

            
            commands.Add("validateUser", new UserCommand(Action.Select, this));
            commands.Add("registerUser", new UserCommand(Action.Insert, this));
            commands.Add("updateUser", new UserCommand(Action.Update, this));
            commands.Add("deleteUser", new UserCommand(Action.Delete, this));
            commands.Add("deleteTrackBack", new TrackBackCommand(Action.Delete,this));
        }
        public CallBackHelp(System.Web.UI.Control control, string parameter)
        {
            this.SourceControl = control;
            this.Page = control.Page;
            this.parameter = parameter;
            CreateCommand();
            commands[parameter].Excute();
        }
    }

    public class CallBackBase
    {
        #region property

        public System.Web.UI.Control SourceControl;

        protected string parameter;

        protected string[] parameters;

        private Page _page;
        public Page Page
        {
            get
            {
                return _page;
            }
            set
            {
                _page = value;
            }
        }

        public bool CheckControlLength
        {
            get
            {
                return this.SourceControl.Controls.Count == 0;
            }
        }

        public void LoadControl(System.Web.UI.Control controlName)
        {
            this._readyControl = controlName;
            this.SourceControl.Controls.Clear();
            this.SourceControl.Controls.Add(ReadyControl);
        }
        public void LoadControl(string controlName)
        {
            LoadControl("control", controlName);
        }

        public void LoadControl(string path, string controlName)
        {
            //path + "//" + 
            this._readyControl = Page.LoadControl(controlName);
            this.SourceControl.Controls.Clear();
            this.SourceControl.Controls.Add(this.ReadyControl);
        }

        private System.Web.UI.Control _readyControl;
        public System.Web.UI.Control ReadyControl
        {
            get
            {
                if (_readyControl == null)
                {
                    _readyControl = new LiteralControl();
                }
                return _readyControl;
            }
        }

        #endregion

    }
}
